package com.ruoyi.web.controller.api.article;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.system.domain.bo.PArticleBo;
import com.ruoyi.system.domain.vo.PArticleVo;
import com.ruoyi.system.service.IPArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @Description:
 * @Author: wk
 * @Date: 2022/8/16 8:50
 * @Version: 1.0
 */
@Api(tags = {"前端-心理咨询文章管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/article")
public class ArticleApiController {
    private final IPArticleService iPArticleService;

    @ApiOperation("查询心理咨询文章列表")
    @GetMapping("/list")
    public TableDataInfo<PArticleVo> list(PArticleBo bo, PageQuery pageQuery) {
        bo.setStatus("2");
        return iPArticleService.queryLeftPageList(bo, pageQuery);
    }

    @ApiOperation("获取心理咨询文章详细信息")
    @GetMapping("/{id}")
    public R<PArticleVo> getInfo(@ApiParam("主键")
                                 @NotNull(message = "主键不能为空")
                                 @PathVariable("id") Long id) {
        return R.ok(iPArticleService.queryById(id));
    }

    @ApiOperation("新增心理咨询文章")
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PArticleBo bo) {
        iPArticleService.insertFontByBo(bo);
        return R.ok();
    }

}
